﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TrainingsApp.Model;
using TrainingsApp.Logic;

namespace TrainingsApp.IPADApp {
    public partial class Login : System.Web.UI.Page {
        protected void Page_Load(object sender, EventArgs e) {

        }

        protected void btnLogin_Click(object sender, EventArgs e) {
            string secCode = txtImgeCode.Text;
            if (string.Compare(secCode, Convert.ToString(Session["SK_SecrityCode"]), false) == 0) {

                string account = this.txtAcctId.Text.Replace("'", "''");
                string password = this.txtPass.Text.Replace("'", "''");

                UserContext user = null;

                try {

                    user = Sys_Permission_Logic.UserLogin(account, password);
                    //user = Sys_Permission_Logic.UserLogin(account, string.IsNullOrEmpty(password) ? password : WisDragon.Framework.Utility.DesSecurity.DesEncrypt(password));
                }
                catch (Exception ex) { MessageBox.Show(ex.Message); }

                if (user == null) {
                    MessageBox.Show("登录失败，请重新登录!", MessageBoxIcon.Error);
                }
                else {
                    user = Sys_Permission_Logic.GetUserInfo(user.UserName);
                    Session["CurContext"] = user;
                    Response.Redirect("~/Master/SchoolManager.aspx");
                }
            }
            else {
                MessageBox.Show("验证码输入不正确!", MessageBoxIcon.Error);
            }
        }
    }
}